<?php
class Manager_CommentsController extends Zendvn_Controller_Action{
	private $_arrParam;
	private $_mainAction;
	protected $_currentController;
	protected $_paginator = array(
									'itemCountPerPage' => 5,
									'pageRange' => 3,
								  ); 
	
	public  function init()
	{
	    $this->_arrParam = $this->_request->getParams();	
        $this->loadTemplate(TEMPLATE_PATH . '/admin/system');
        
        $this->_mainAction = $this->_arrParam['module'] . '/' . $this->_arrParam['controller'] . '/index';	
	    $this->view->arrParam = $this->_arrParam; 
	    
	    $tbl_category         = new Manager_Model_categoryproduct();
	    $this->view->list     = $tbl_category->list_category();
	    $this->view->cat_id   = $tbl_category->list_cat();
       
	}
	
	public function indexAction()
	{
	
	    $this->view->Title = "Comments Manager";
		$this->view->headTitle($this->view->Title,true);
		
		$this->view->headScript()->appendFile($this->view->baseUrl().'/js/balloontip.js');
	    $this->view->headLink()->appendStylesheet($this->view->baseUrl().'/css/balloontip.css');
		
		$tbl_category = new Manager_Model_comments();
		$id=$this->_arrParam['id'];
		
		$tbl_details = new Manager_Model_detailsproduct();
		
		if($this->_request->getCookie('secnews')==NULL){ $secnews=-1; } 
		else { $secnews=$this->_request->getCookie('secnews');}	 
		
		if($this->_request->getCookie('catnews')==NULL){ $cat=-1; } 
		else { $cat=$this->_request->getCookie('catnews');}	 
		
		if($this->_request->getCookie('tours')==NULL){ $product=-1; } 
		else { $product=$this->_request->getCookie('tours');}	 
		
		if (isset($id)==FALSE) $id=-1;
		
	    $this->view->cat=$tbl_details->list_category($secnews);
		$this->view->product=$tbl_details->list_product($cat);
		
		
		if($this->_request->getPost('keyword')!=NULL)
		  {
			 $keyword=$this->_request->getParam('keyword');
			 $this->view->keyword=$keyword;
			 if($this->_request->getCookie('status')==NULL){ $status=-1; 
	      } 
	    else 
	      {
	    	  $status=$this->_request->getCookie('status');
	      }

     	  $listArticles = $tbl_category->searchkq($keyword,$status,$id,$product);
     	   $currentPage = 1;
         	 $i = $this->_getParam('page',1);
         	 if(!empty($i))
         	 {
				 $currentPage = $i;
          	 }
         	 $paginator = Zend_Paginator::factory($listArticles);
         	 $paginator->setItemCountPerPage(10)
                    ->setPageRange(5)
                    ->setCurrentPageNumber($currentPage);
         	 $this->view->paginator = $paginator;
         	
         	 
		 } 
    	else 
         {
			if($this->_request->getCookie('status')==NULL){ $status=-1; } 
			else { $status=$this->_request->getCookie('status');}
	 	
     	 	$listArticles = $tbl_category->listItemabout($status,$id,$product);
     	 	
     	 	$currentPage = 1;
         	 $i = $this->_getParam('page',1);
         	 if(!empty($i))
         	 {
          	    $currentPage = $i;
          	}
         	 $paginator = Zend_Paginator::factory($listArticles);
         	 $paginator->setItemCountPerPage(45)
                    ->setPageRange(10)
                    ->setCurrentPageNumber($currentPage);
         	 $this->view->paginator = $paginator;
     	 } 
	   
	}
	
    public  function infoAction()
	{
	    $tbl_comments = new Manager_Model_comments();
		$id=$this->_request->getParam('id');
		
		$this->view->info=$tbl_comments->getrow($id);
		$this->_helper->layout->disableLayout();
		
		
	}
		
    public function statusAction()
    {
		  $db = Zend_Registry::get('connectDb');
	      $arrParam=$this->_arrParam;
	      if($this->_arrParam['type'] == 'multi')
	      {
			if(count($arrParam['cid'])>0)
			   {
					$ids = implode(',', $arrParam['cid']);
					$status = ($arrParam['s'] == 0 )? 1:0;  
					$where = 'id IN (' . $ids . ')'; 
				    $db->update('comments',array('published'=>$status),$where);
			    }
		   }
		else 
		        {
					$status = ($arrParam['s'] == 0 )? 1:0;            
					$where ="id=$arrParam[id]";  
					$db->update('comments',array('published'=>$status),$where);			
			   	 
		        }
		 header("location:".$_SERVER['HTTP_REFERER']);
		 $this->_helper->viewRenderer->setNoRender();
	   }	
   
}